<?php

namespace App\Console\Commands;

use App\Models\Music\Music;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class MusicUpdate extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'music:update';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $query = Music::with('music_check')->where('type_status','<>',0);
        $query->whereHas('music_check', function ($query) {
            $query->where('end_time','<',date('Y-m-d'));
        });
        $res = $query->select('id')->get();
        if(!empty($res)){
            $res = $res->toArray();
            foreach($res as $v){
                $id[] = $v['id'];
            }
        }
        if(!empty($id)) {
            Music::whereIn('id', $id)->update(['type_status' => 0]);
        }
        Log::info('我执行力');
    }
}
